package com.haiwei.poi.common;

/**
 * @author karry@haiwei.com
 **/
public class HaiweiStringUtil{
    
    /**
     * 判断数组中是否有空值
     * @param args
     * @return
     */
    public static boolean hashEmpty(String ... args){
        if(args == null || args.length == 0){
            return true;
        }

        for(int i = 0;i<args.length ;i++){
            if(isEmpty(args[i])){
                return true;
            }
        }

        return false;
    }


    /**
     * 获取字符串的长度
     * @param str
     * @return
     */
    public static long size(String str) {
        if(str == null){
            return 0L;
        }
        str = str.trim();
        return str.length();
    }
    
    
    /**
     * 首字母大写
     * eg:
     * 1. arr -> Arr
     * 2. Arr -> Arr
     * 3. null -> null
     * 4. "" -> ""
     * @param str
     * @return
     */
    public static String toUpperCaseFirstOne(String str) {
        if(str == null || str.trim().length() == 0 ){
            return str;
        }

        char[] arr = str.toCharArray();
        if(Character.isUpperCase(arr[0])){
            return str;
        }

        arr[0] = (char)(arr[0] - 32);

        return new String(arr);

    }


	public static boolean isEmpty(String str) {
		return str == null || str.trim().length() == 0 ;
	}
	
	public static boolean isNotEmpty(String str) {
		return !isEmpty(str);
	}
    
    public static boolean isNotBlank(final CharSequence cs) {
        return !isBlank(cs);
    }
	
    public static boolean isBlank(final CharSequence cs) {
        int strLen;
        if (cs == null || (strLen = cs.length()) == 0) {
            return true;
        }
        for (int i = 0; i < strLen; i++) {
            if (Character.isWhitespace(cs.charAt(i)) == false) {
                return false;
            }
        }
        return true;
    }
    
    /**
     * 移除字符串中所有空格
     * @param cs
     * @return
     */
    public static String removeWhitespace(final CharSequence cs) {
        int strLen;
        if (cs == null || (strLen = cs.length()) == 0) {
            return "";
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < strLen; i++) {
            if (Character.isWhitespace(cs.charAt(i)) == false) {
                sb.append(cs.charAt(i));
            }
        }
        
        return sb.toString();
    }

}
